set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode='nonstrict';
set hive.exec.max.dynamic.partitions=400;
set hive.exec.max.dynamic.partitions.pernode=400;

insert overwrite table jms_dm.dm_staff_silence_summary_dt
select
     network_code   
    ,network_name   
    ,franchisee_code
    ,franchisee_name
    ,agent_code     
    ,agent_name      
    ,stat_range    
    ,nvl(sum(is_incumbency),0) as on_job_cnt                 --是否在职
    ,nvl(sum(is_enable    ),0) as staff_enable_cnt           --是否启用员工
    ,nvl(sum(is_act       ),0) as activity_staff_cnt         --活跃用户数
    ,nvl(sum(is_silence   ),0) as silence_staff_cnt          --静默员工
    ,nvl(sum(is_scan      ),0) as operate_scan_cnt           --操作扫描员工
    ,nvl(sum(is_jms       ),0) as jms_activity_staff_cnt     --JMS
    ,nvl(sum(is_zt        ),0) as rabbit_app_act_cnt         --智兔APP
    ,nvl(sum(is_jc        ),0) as decision_making_act_cnt    --决策APP
    ,nvl(sum(is_in        ),0) as infield_act_cnt            --内场APP
    ,nvl(sum(is_out       ),0) as outfield_act_cnt           --外场APP
    ,nvl(sum(is_pc        ),0) as jms_pc_act_cnt             --PC
    ,date_add('{{ execution_date | cst_ds }}',1) as dt
from jms_dm.dm_staff_silence_detail_dt
where dt = '{{ execution_date | date_add(1) | cst_ds }}'
group by network_code   
        ,network_name   
        ,franchisee_code
        ,franchisee_name
        ,agent_code     
        ,agent_name    
        ,stat_range    
distribute by pmod(hash(rand()),1);
